﻿using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using TTGameEngine;
/*
 * PuppetEditor
 *
 *
 *
 * 依赖：
 *
 * ！不写重复代码！
 * @author TTun
 * @date 7/13/2017 4:41:01 PM
 */
[CanEditMultipleObjects]
[CustomEditor(typeof(Puppet))]
public class PuppetEditor : Editor {
    SerializedObject scriptObj;
    Puppet obj;

    const int ToolsCount = 10;
    bool[] allValuePrefab = new bool[ToolsCount];

    SerializedProperty m_objType;
    SerializedProperty serverObjDataID;
    SerializedProperty objGID;
    SerializedProperty nameEn;
    SerializedProperty nameCn;
    SerializedProperty objTF;
    SerializedProperty moveInfo;
    SerializedProperty m_lookingRotationSpeed;
    SerializedProperty moveColliderRange;

    //动画
    SerializedProperty standAnimName;
    SerializedProperty attackStandAnimName;
    SerializedProperty showAnimName;
    SerializedProperty runAnimName;
    SerializedProperty lightHurtForwardAnimName;
    SerializedProperty lightHurtBackwardAnimName;
    SerializedProperty heavyHurtForwardAnimName;
    SerializedProperty heavyHurtBackwardAnimName;
    SerializedProperty knowDownBackwardAnimName;
    SerializedProperty knowDownForwardAnimName;
    SerializedProperty climbUpForwardAnimName;
    SerializedProperty climbUpBackwardAnimName;
    SerializedProperty winAnimName;
    SerializedProperty deadAnimName;
    SerializedProperty reloadAnimName;
    SerializedProperty m_animPlayer;
    SerializedProperty m_animation;
    SerializedProperty deadRemainsPrefab;

    //战斗
    SerializedProperty ActiveSkillPostCD;

    //Sounds
    SerializedProperty footAnimPoint1;
    SerializedProperty footAnimPoint2;
    SerializedProperty deathSoundNames;
    SerializedProperty heavyDamageSoundNames;
    SerializedProperty lightDamageSoundNames;
    SerializedProperty pushbackDamageSoundNames;
    SerializedProperty footstepSoundNames;
    SerializedProperty reloadSoundPlayTime;
    SerializedProperty reloadSoundName;

    //FPS
//     SerializedProperty fpsAtkCD;
//     SerializedProperty fpsTime;
//     SerializedProperty fpsBulletTag;
    SerializedProperty fpsManPrefab;
    SerializedProperty fpsModelOffset;
    SerializedProperty fpsMuzzleEffectPrefab;
    SerializedProperty fpsAttackStandAnimName;
    SerializedProperty fpsAttackAnimName;
    SerializedProperty fpsMaxAttackShowTime;
    void OnEnable() {
        scriptObj = new SerializedObject(target);
        obj = target as Puppet;

        m_objType = scriptObj.FindProperty("m_objType");
        serverObjDataID = scriptObj.FindProperty("serverObjDataID");
        objGID = scriptObj.FindProperty("objGID");
        nameEn = scriptObj.FindProperty("nameEn");
        nameCn = scriptObj.FindProperty("nameCn");
        objTF = scriptObj.FindProperty("objTF");
        moveInfo = scriptObj.FindProperty("m_moveInfo");
        m_lookingRotationSpeed = scriptObj.FindProperty("m_lookingRotationSpeed");
        moveColliderRange = scriptObj.FindProperty("moveColliderRange");

        standAnimName = scriptObj.FindProperty("standAnimName");
        attackStandAnimName = scriptObj.FindProperty("attackStandAnimName");
        showAnimName = scriptObj.FindProperty("showAnimName");
        runAnimName = scriptObj.FindProperty("runAnimName");
        lightHurtForwardAnimName = scriptObj.FindProperty("lightHurtForwardAnimName"); ;
        lightHurtBackwardAnimName = scriptObj.FindProperty("lightHurtBackwardAnimName"); ;
        heavyHurtForwardAnimName = scriptObj.FindProperty("heavyHurtForwardAnimName"); ;
        heavyHurtBackwardAnimName = scriptObj.FindProperty("heavyHurtBackwardAnimName"); ;
        knowDownBackwardAnimName = scriptObj.FindProperty("knowDownBackwardAnimName");
        knowDownForwardAnimName = scriptObj.FindProperty("knowDownForwardAnimName");
        climbUpForwardAnimName = scriptObj.FindProperty("climbUpForwardAnimName");
        climbUpBackwardAnimName = scriptObj.FindProperty("climbUpBackwardAnimName");
        winAnimName = scriptObj.FindProperty("winAnimName");
        deadAnimName = scriptObj.FindProperty("deadAnimName");
        reloadAnimName = scriptObj.FindProperty("reloadAnimName");
        m_animPlayer = scriptObj.FindProperty("m_animPlayer");
        m_animation = scriptObj.FindProperty("m_animation");
        deadRemainsPrefab = scriptObj.FindProperty("deadRemainsPrefab");

        ActiveSkillPostCD = scriptObj.FindProperty("ActiveSkillPostCD");


        footAnimPoint1 = scriptObj.FindProperty("footAnimPoint1");
        footAnimPoint2 = scriptObj.FindProperty("footAnimPoint2");
        deathSoundNames = scriptObj.FindProperty("deathSoundNames");
        heavyDamageSoundNames = scriptObj.FindProperty("heavyDamageSoundNames");
        lightDamageSoundNames = scriptObj.FindProperty("lightDamageSoundNames");
        pushbackDamageSoundNames = scriptObj.FindProperty("pushbackDamageSoundNames");
        footstepSoundNames = scriptObj.FindProperty("footstepSoundNames");
        reloadSoundPlayTime = scriptObj.FindProperty("reloadSoundPlayTime");
        reloadSoundName = scriptObj.FindProperty("reloadSoundName");


//         fpsAtkCD = scriptObj.FindProperty("fpsAtkCD");
//         fpsTime = scriptObj.FindProperty("fpsTime");
//         fpsBulletTag = scriptObj.FindProperty("fpsBulletTag");
        fpsManPrefab = scriptObj.FindProperty("fpsManPrefab");
        fpsModelOffset = scriptObj.FindProperty("fpsModelOffset");
        fpsMuzzleEffectPrefab = scriptObj.FindProperty("fpsMuzzleEffectPrefab");
        fpsAttackStandAnimName = scriptObj.FindProperty("fpsAttackStandAnimName");
        fpsAttackAnimName = scriptObj.FindProperty("fpsAttackAnimName");
        fpsMaxAttackShowTime = scriptObj.FindProperty("fpsMaxAttackShowTime");

        for(int i = 0; i < allValuePrefab.Length; i++) {
            allValuePrefab[i] = true;
        }

        allValuePrefab[9] = false;

    }

    public override void OnInspectorGUI() {
        if(GUILayout.Button("ActiveObj")) {
            obj.ActiveObj();
        }
        scriptObj.Update();

        EditorGUILayout.PropertyField(m_objType);
        EditorGUILayout.PropertyField(serverObjDataID);
        EditorGUILayout.PropertyField(objGID);
        EditorGUILayout.PropertyField(nameEn);
        EditorGUILayout.PropertyField(nameCn);
        EditorGUILayout.PropertyField(objTF);

        allValuePrefab[0] = EditorGUILayout.Foldout(allValuePrefab[0], "Move -----");
        if(allValuePrefab[0]) {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(m_lookingRotationSpeed);
            EditorGUILayout.PropertyField(moveColliderRange);
            scriptObj.ApplyModifiedProperties();
            //只读
            EditorGUILayout.PropertyField(moveInfo, true);
            scriptObj.Update();
            EditorGUI.indentLevel--;
        }
        allValuePrefab[3] = EditorGUILayout.Foldout(allValuePrefab[3], "Battle -----");
        if(allValuePrefab[3]) {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(ActiveSkillPostCD);
            EditorGUI.indentLevel--;
        }
        allValuePrefab[4] = EditorGUILayout.Foldout(allValuePrefab[4], "FPS -----");
        if(allValuePrefab[4]) {
            EditorGUI.indentLevel++;
//             EditorGUILayout.PropertyField(fpsAtkCD);
//             EditorGUILayout.PropertyField(fpsTime);
//             EditorGUILayout.PropertyField(fpsBulletTag);
            EditorGUILayout.PropertyField(fpsManPrefab);
            EditorGUILayout.PropertyField(fpsModelOffset);
            EditorGUILayout.PropertyField(fpsMuzzleEffectPrefab);
            EditorGUILayout.PropertyField(fpsAttackStandAnimName);
            EditorGUILayout.PropertyField(fpsAttackAnimName);
            EditorGUILayout.PropertyField(fpsMaxAttackShowTime);
            EditorGUI.indentLevel--;
        }
        allValuePrefab[1] = EditorGUILayout.Foldout(allValuePrefab[1], "Animation -----");
        if(allValuePrefab[1]) {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(standAnimName);
            EditorGUILayout.PropertyField(attackStandAnimName);
            EditorGUILayout.PropertyField(showAnimName);
            EditorGUILayout.PropertyField(runAnimName);
            EditorGUILayout.PropertyField(lightHurtForwardAnimName);
            EditorGUILayout.PropertyField(lightHurtBackwardAnimName);
            EditorGUILayout.PropertyField(heavyHurtForwardAnimName);
            EditorGUILayout.PropertyField(heavyHurtBackwardAnimName);
            EditorGUILayout.PropertyField(knowDownBackwardAnimName);
            EditorGUILayout.PropertyField(knowDownForwardAnimName);
            EditorGUILayout.PropertyField(climbUpForwardAnimName);
            EditorGUILayout.PropertyField(climbUpBackwardAnimName);
            EditorGUILayout.PropertyField(winAnimName);
            EditorGUILayout.PropertyField(deadAnimName);
            EditorGUILayout.PropertyField(reloadAnimName);
            EditorGUILayout.PropertyField(m_animation);
            EditorGUILayout.PropertyField(deadRemainsPrefab);
            scriptObj.ApplyModifiedProperties();
            //只读
            EditorGUILayout.PropertyField(m_animPlayer, true);
            scriptObj.Update();
            EditorGUI.indentLevel--;
        }

        allValuePrefab[2] = EditorGUILayout.Foldout(allValuePrefab[2], "Sounds -----");
        if(allValuePrefab[2]) {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(deathSoundNames, true);
            EditorGUILayout.PropertyField(heavyDamageSoundNames, true);
            EditorGUILayout.PropertyField(lightDamageSoundNames, true);
            EditorGUILayout.PropertyField(pushbackDamageSoundNames, true);
            EditorGUILayout.PropertyField(footAnimPoint1);
            EditorGUILayout.PropertyField(footAnimPoint2);
            EditorGUILayout.PropertyField(footstepSoundNames, true);
            EditorGUILayout.PropertyField(reloadSoundPlayTime);
            EditorGUILayout.PropertyField(reloadSoundName);

            EditorGUI.indentLevel--;
        }
//         if (GUILayout.Button(new GUIContent("SetState", "Test Button"), EditorStyles.miniButton))
//         {
//
        int oldState = (int)obj.StateID;
        int state = (int)(PuppetStateID)EditorGUILayout.EnumPopup(new GUIContent("CurState", "hint"), (PuppetStateID)oldState);
        if(state != oldState) {
            obj.SetState((PuppetStateID)state);
        }

        allValuePrefab[9] = EditorGUILayout.Foldout(allValuePrefab[9], "All Values -----");
        if(allValuePrefab[9]) {
            base.OnInspectorGUI();
        }

        scriptObj.ApplyModifiedProperties();
    }
}